package com.kuang.demo.service;

import com.kuang.demo.bo.zzy.StorageBo.PageLimit3;
import com.kuang.demo.bo.zzy.StorageBo.StorageListRe;
import com.kuang.demo.bo.zzy.TotalItem;
import com.kuang.demo.mapper.StorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StorageServiceImpl implements StorageService {
    @Autowired
    StorageMapper storageMapper;

    @Override
    public TotalItem selectStorageList(PageLimit3 pageLimit3) {

        //items
        pageLimit3.setPage(pageLimit3.getLimit()*(pageLimit3.getPage() - 1));
        List<StorageListRe> list = storageMapper.selectStorageByLimit(pageLimit3);

        //这里查询total
        int total = storageMapper.selectAllStorage(pageLimit3);


        TotalItem totalItem = new TotalItem();
        totalItem.setTotal(total);
        totalItem.setItems(list);
        return totalItem;
    }

    @Override
    public StorageListRe updateStorage(StorageListRe storageListRe) {
        storageMapper.updateStorage(storageListRe);

        //改完之后查询
        StorageListRe storageListRe1 = storageMapper.selectStorageById(storageListRe.getId());

        return storageListRe1;
    }

    @Override
    public void deleteStorage(Integer id) {
        storageMapper.deleteById(id);
    }
}
